package com.ruoyi.web.controller.wb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbInform;
import com.ruoyi.wb.service.IWbInformService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 消息Controller
 *
 * @author ruoyi
 * @date 2024-10-14
 */
@Api(tags="消息列表管理")
@RestController
@RequestMapping("/wb/wbInform")
public class WbInformController extends BaseController {
    @Autowired
    private IWbInformService wbInformService;

    /**
     * 查询消息列表
     */
    @ApiOperation("查询消息列表")
    @GetMapping("/list")
    public TableDataInfo list(WbInform wbInform) {
        startPage();
        List<WbInform> list = wbInformService.selectWbInformList(wbInform);
        return getDataTable(list);
    }

    /**
     * 查询消息列表
     */
    @ApiOperation("查询消息列表")
    @GetMapping("/getCount")
    public AjaxResult getCount() {
        return AjaxResult.success(wbInformService.getCount());
    }


    /**
     * 导出消息列表
     */
    @ApiOperation("导出消息列表")
    @Log(title = "消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbInform wbInform) {
        List<WbInform> list = wbInformService.selectWbInformList(wbInform);
        ExcelUtil<WbInform> util = new ExcelUtil<WbInform>(WbInform.class);
        util.exportExcel(response, list, "消息数据");
    }

    /**
     * 获取消息详细信息
     */
    @ApiOperation("获取消息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wbInformService.selectWbInformById(id));
    }

    /**
     * 新增消息
     */
    @ApiOperation("新增消息")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbInform wbInform) {
        return toAjax(wbInformService.insertWbInform(wbInform));
    }

    /**
     * 修改消息
     */
    @ApiOperation("修改消息")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbInform wbInform) {
        return toAjax(wbInformService.updateWbInform(wbInform));
    }

    /**
     * 删除消息
     */
    @ApiOperation("删除消息")
    @Log(title = "消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wbInformService.deleteWbInformByIds(ids));
    }
}